package com.codinghero.example.longleg;

import java.io.File;
import java.util.Arrays;

import com.codinghero.util.CodecUtils;
import com.codinghero.util.FileUtils;

public class RenameImage {

	private static final String RENAMED_PREFIX = "r";
	
	private static final String RENAMED_JOIN = "_";

	public static void main(String[] args) {
		File rootFolder = new File(Constant.ORIG.FOLDER_PATH);
		File[] files = rootFolder.listFiles();
		Arrays.sort(files, new FileModifyTimeComparator());
		for (File file : files) {
			if (!file.getName().startsWith(RENAMED_PREFIX + RENAMED_JOIN)) {
				final String md5 = CodecUtils.md5(FileUtils.getContent(file.getPath()));
				final String fileType = FileUtils.getFileType(file.getPath());
				
				final String renameFilePath = 
						Constant.ORIG.FOLDER_PATH + File.separator + 
						RENAMED_PREFIX + 
						RENAMED_JOIN + file.lastModified() + 
						RENAMED_JOIN + md5 + 
						RENAMED_JOIN + "0." 
						+ fileType;
				final File renameFile = new File(renameFilePath);
				file.renameTo(renameFile);
			}
		}
	}
}
